package com.fuyd.pms.entity.base;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.Date;

/**
 * 实体类的基类，由自己定义的策略生成随机的id，适用于商品、订单、用户等id暴露在外的数据，防止脱裤。
 * 基类统一定义id、created、updated、delete的属性名称、数据类型、列名映射及生成策略.
 * Oracle需要每个Entity独立定义id的SEQUCENCE时，不继承于本类而改为实现一个Idable的接口。
 * Created by fuyongde on 2015/12/23.
 */
@MappedSuperclass
public abstract class BaseEntityGen {
    /**id**/
    private String id;
    /**创建时间**/
    private Date created;
    /**更新时间**/
    private Date updated;
    /**是否删除**/
    private boolean isDelete;

    @Id
    @Length(max = 128)
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "GenGenerator")
    @GenericGenerator(name = "GenGenerator", strategy = "com.fuyd.pms.entity.base.GenGenerator")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public boolean getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(boolean delete) {
        isDelete = delete;
    }
}
